import 'package:flutter/material.dart';
import '../check_list/state.dart';
import '../../../app_files.dart';
import '../widget/main_item_widget.dart';

class CheckListWidget extends StatelessWidget {
  final CheckListModel model;
  final Function(String, int) onLoad;
  final String tag;

  const CheckListWidget({this.onLoad, this.model, this.tag});

  Widget itemBuilder(BuildContext context, int index) {
    CheckListItemModel item = model.items[index];
    return MainItemWidget.communityBuilder(context, item);
  }

  @override
  Widget build(BuildContext context) {
    if (model.items == null) {
      onLoad(tag, 1);
      return Center(
        child: MyLoadingWidget(),
      );
    }
    return CustomRefreshList(
      child: model.items.length == 0
          ? Container(
              child: Center(
                child: Stack(
                  children: <Widget>[
                    MyEmptyItemWidget(),
                  ],
                ),
              ),
            )
          : ListView.builder(
              itemBuilder: itemBuilder,
              itemCount: model.items.length,
              shrinkWrap: true,
              physics: NeverScrollableScrollPhysics(),
            ),
      onRefresh: (String tag) => onLoad(tag, 1),
      onLoading: (String tag, int page) => onLoad(tag, page),
      currentPage: model.currentPage,
      tag: tag,
      refreshController: model.refreshController,
    );
  }
}
